﻿using FTBS.Models.BLO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FTBS.Models.Entities;

namespace FTBS.Controllers
{
    public class CustomerController : Controller
    {
        private UserBLO _userBlo = new UserBLO();

        /// <summary>
        /// display all customers
        /// </summary>
        /// <returns></returns>
        /// <author>hungph</author>
        public ActionResult Index()
        {
            return View(_userBlo.DisplayAllCustomers());
        }

        /// <summary>
        /// active customer
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <author>hungph</author>
        public ActionResult Active(String id)
        {
            User user = _userBlo.LoadUserByUserName(id);
            if (user == null)
            {
                return HttpNotFound();
            }
            bool isActive = _userBlo.ActiveUser(user);
            return RedirectToAction("Index");
        }

        /// <summary>
        /// deactive customer
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <author>hungph</author>
        public ActionResult Deactive(String id)
        {
            User user = _userBlo.LoadUserByUserName(id);
            if (user == null)
            {
                return HttpNotFound();
            }
            bool isActive = _userBlo.DeactiveUser(user);
            return RedirectToAction("Index");
        }
        /// <summary>
        /// Delete user
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Redirect to Index page</returns>
        /// <author>hungph</author>
        [HttpDelete, ActionName("Delete")]
        public ActionResult Delete(String id)
        {
            User user = _userBlo.LoadUserByUserName(id);
            if (user == null)
            {
                return HttpNotFound();
            }
            _userBlo.DeleteUser(user);
            return RedirectToAction("Index");
        }

    }
}
